<script setup>
import {onMounted, ref} from "vue";
import {statusTagText, statusTagType, SubmitVO} from "@/model/submit.js";
import {diffTagType, diffTagText} from "@/model/pool.js";
import {r_s_list} from "@/request/api/submit.js";
import {useLoginStorage} from "@/stores/loginStorage.js";
import {useRouter} from "vue-router";

const loginStore = useLoginStorage();
const router = useRouter();

const submitVOsData = ref([{...SubmitVO}]);


const list = () => {
  const userId = loginStore.getUserInfo.userId;
  console.log("userID: ", userId)
  r_s_list(userId).then(data => {
    submitVOsData.value = data;

    /*    // 或者逐个 push
        for (let i = 0; i < data.length; i++) {
          submitVOsData.value.push({
            poolVO: data[i].poolVO,
            status: data[i].status,
            code: data[i].code,
            codeType: data[i].codeType,
            useMilTime: data[i].useMilTime,
            useKbMemory: data[i].useKbMemory,
            errorTip: data[i].errorTip,
            putTime: data[i].putTime
          });
        }*/
  });
}

const info = (submitId) => {
  router.push(`/submit/info-${submitId}`);
}

onMounted(() => {
  if (submitVOsData.value[0].poolVO.poolId === '')
    submitVOsData.value = null;

  if (loginStore.getIsLogin)
    list();
});

</script>

<template>
  <div class="index-all">
    <div>
      <span class="title">提 交 记 录</span>
    </div>
    <p>
      <el-table :data="submitVOsData" empty-text="暂 无 数 据">
        <el-table-column prop="poolVO.poolId" label="题 号" width="150px"/>
        <el-table-column prop="poolVO.title" label="标 题" width="350px"/>
        <el-table-column prop="poolVO.difficulty" label="难 度" width="150px">
          <template #default="scope">
            <el-tag :type="diffTagType(scope.row.poolVO.difficulty)" effect="plain">
              {{ diffTagText(scope.row.poolVO.difficulty) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状 态" width="150px">
          <template #default="scope">
            <el-tag :type="statusTagType(scope.row.status)" effect="light">
              {{ statusTagText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="putTime" label="提交时间"/>
        <el-table-column prop="putTime" label="操 作">
          <template #default="scope">
            <el-button type="primary" link @click="info(scope.row.submitId)">详 情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </p>
  </div>
</template>

<style scoped>
.title {
  font-size: 20px;
  margin-right: 50px;
}

.el-table {
  width: 90%;
  color: black;
}
</style>